/** @jsxRuntime automatic */
/** @jsxImportSource ../xml-runtime */
import { formatAudio, getFFVideoFormat } from 'auto-cut-video-lib/FCP'

function Audio({ pathObject, mediaInfo, sequenceInfo }) {
  return (
    <resources>
      {/* sequence format */}
      <format
        id="r1"
        name={formatAudio}
        frameDuration={`${sequenceInfo.multiple}/${
          sequenceInfo.frameRate * sequenceInfo.multiple
        }s`}
        width="1920"
        height="1080"
      ></format>
      <asset
        id="r2"
        name={pathObject.name}
        start="0s"
        duration={`${mediaInfo.duration * mediaInfo.multiple}/${
          mediaInfo.multiple
        }s`}
        hasAudio="1"
        format="r3"
        audioSources="1"
        audioChannels={mediaInfo.channelCount}
        audioRate={mediaInfo.sampleRate}
      >
        <media-rep
          kind="original-media"
          // FCP中，src不允许汉字，其他地方均允许
          src={encodeURI(pathObject.base)}
        ></media-rep>
      </asset>
      {/* 素材format */}
      <format
        id="r3"
        frameDuration={`${sequenceInfo.multiple}/${
          sequenceInfo.frameRate * sequenceInfo.multiple
        }s`}
      ></format>
    </resources>
  )
}

function Video({ pathObject, mediaInfo, sequenceInfo }) {
  return (
    <resources>
      {/* sequence format */}
      <format
        id="r1"
        name={getFFVideoFormat({
          ...mediaInfo,
          frameRate: sequenceInfo.frameRate,
        })}
        frameDuration={`${sequenceInfo.multiple}/${
          sequenceInfo.frameRate * sequenceInfo.multiple
        }s`}
        width={mediaInfo.width}
        height={mediaInfo.height}
      ></format>
      <asset
        id="r2"
        name={pathObject.name}
        start="0s"
        duration={`${mediaInfo.durationTs}/${mediaInfo.timeBase}s`}
        hasVideo="1"
        hasAudio="1"
        format="r3"
        videoSources="1"
        audioSources="1"
        audioChannels={mediaInfo.channelCount}
        audioRate={mediaInfo.sampleRate}
      >
        <media-rep
          kind="original-media"
          // FCP中，src不允许汉字，其他地方均允许
          src={encodeURI(pathObject.base)}
        ></media-rep>
      </asset>
      {/* 素材format */}
      <format
        id="r3"
        frameDuration={`${mediaInfo.frameDuration}/${mediaInfo.timeBase}s`}
        width={mediaInfo.width}
        height={mediaInfo.height}
      ></format>
    </resources>
  )
}

export const Resources = { Audio, Video }
